export const getFormatTime = time => {
	let dateTime = new Date(time);
	let no1new = dateTime.valueOf();
	let year = dateTime.getFullYear();
	let month = dateTime.getMonth() + 1;
	let day = dateTime.getDate();
	let hour = dateTime.getHours();
	let minute = dateTime.getMinutes();
	let second = dateTime.getSeconds();
	let now = new Date();
	let now_new = now.valueOf();
	let milliseconds = 0;
	let timeSpanStr;
	milliseconds = now_new - no1new;
	if (milliseconds <= 1000 * 60 * 1) {
		timeSpanStr = '刚刚';
	} else if (1000 * 60 * 1 < milliseconds && milliseconds <= 1000 * 60 * 60) {
		timeSpanStr = Math.floor((milliseconds / (1000 * 60))) + '分钟前';
	} else if (Math.floor(milliseconds / (1000 * 60 * 60)) < 24) {
		timeSpanStr = Math.floor(milliseconds / (1000 * 60 * 60)) + '小时前';
	} else if (Math.floor(milliseconds / (1000 * 60 * 60 * 24)) < 31) {
		timeSpanStr = Math.floor(milliseconds / (1000 * 60 * 60 * 24)) + '天前';
	} else if (Math.floor(milliseconds / (1000 * 60 * 60 * 24 * 31)) < 12) {
		timeSpanStr = Math.floor(milliseconds / (1000 * 60 * 60 * 24 * 31)) + '个月前';
	} else {
		timeSpanStr = time
	}

	return timeSpanStr;
}

// 金额只能输入数字,最多两位小数
export const checkAmount = amount => {
	const inputRule = /^\d+(\.\d{0,2})?$/
	if (!inputRule.test(amount)) {
		return false
	} else {
		return true
	}
}

// 金额只能输入数字,最多三位小数
export const checkAmountThree = amount => {
	const inputRule = /^\d+(\.\d{0,3})?$/
	if (!inputRule.test(amount)) {
		return false
	} else {
		return true
	}
}
//手机号码隐藏中间四位
export const dealTel = (val) => {
	//先判断是不是手机号 是手机号就隐藏 不是展示原来的内容
	var myreg = /^[1][2,3,4,5,6,7,8,9][0-9]{9}$/;
	var regPhone = /^[1][2,3,4,5,6,7,8,9][0-9]{12}$/;
	//如果不是手机号 也不是注销后的手机号+3位数（注册次数，不足补零）
	if ((!myreg.test(val))&&(!regPhone.test(val))) {
		return val;
	} else {
		var reg = myreg.test(val)? (/^(\d{3})\d{4}(\d{4})$/):(/^(\d{3})\d{4}(\d{7})$/)
		return val.replace(reg, "$1****$2")
	}
}
